package dto;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import util.SearchOperator;

/**
 * DTO para busquedas
 * <AtributoEntidad, <ValorABuscar, OperadorDeBusqueda> >
 * 
 * @author nfinelli
 */
public class SearchDTO {
	
	private Map<String, CriteriaDTO> criteria = new HashMap<String, CriteriaDTO>();

	public void addCriteria(String attribute, String value, SearchOperator operator) {

		criteria.put(attribute, new CriteriaDTO(value, operator));
	}
	
	public void addCriteria(String attribute, String value, SearchOperator operator, String alias) {

		criteria.put(attribute, new CriteriaDTO(value, operator, alias));
	}
	
	public void addBeetwenCriteria(String attribute, Date valueA, Date valueB) {
		
		criteria.put(attribute, new CriteriaDTO(valueA, valueB, SearchOperator.BEETWEN));
	}

	public Map<String, CriteriaDTO> getCriterias() {
		return criteria;
	}
	

	public class CriteriaDTO {
	
		private String value;
		
		private Date valueA;
		
		private Date valueB;
		
		private String alias;
		
		private SearchOperator operator;
		
		public CriteriaDTO(String value, SearchOperator operator) {
			this.value = value;
			this.operator = operator;
		}
		
		public CriteriaDTO(Date valueA, Date valueB, SearchOperator operator) {
			this.valueA = valueA;
			this.valueB = valueB;
			this.operator = operator;
		}

		public CriteriaDTO(String value, SearchOperator operator, String alias) {
			this.value = value;
			this.operator = operator;
			this.alias = alias;
		}
		
		public boolean hasValues() {
			if ( (value != null && !"".equals(value.trim()) ) || (valueA != null && valueB != null) ) {
				return true;
			}
			return false;
		}
	
		public String getValue() {
			return value;
		}

		public Date getValueA() {
			return valueA;
		}

		public Date getValueB() {
			return valueB;
		}
		
		public String getAlias() {
			return alias;
		}

		public SearchOperator getOperator() {
			return operator;
		}
	}	
}